package com.carepad.dao;

import com.carepad.entity.RecordItems;
import com.carepad.entity.RecordItemsExample;
import com.carepad.entity.mapper.RecordItemViewMapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

public interface RecordItemsMapper {

	int countByExample(RecordItemsExample example);

	int deleteByExample(RecordItemsExample example);

	int deleteByPrimaryKey(Integer uid);

	int insert(RecordItems record);

	int insertSelective(RecordItems record);

	List<RecordItems> selectByExample(RecordItemsExample example);

	RecordItems selectByPrimaryKey(Integer uid);

	int updateByExampleSelective(@Param("record") RecordItems record,
			@Param("example") RecordItemsExample example);

	int updateByExample(@Param("record") RecordItems record,
			@Param("example") RecordItemsExample example);

	int updateByPrimaryKeySelective(RecordItems record);

	int updateByPrimaryKey(RecordItems record);

	Integer countAll();

	List<? extends Object> findListPaginated(Integer start, Integer size);

	@Select("SELECT * FROM mst_record_items ORDER BY ACTION_ITEM_ORDER")
	@ResultMap(value = "InputItemsMap")
	List<RecordItems> findRecordItemsInputList();

	@Select("SELECT * FROM mst_record_items WHERE DISPLAY_GROUP=#{uId} ORDER BY ACTION_ITEM_ORDER")
	@ResultMap(value = "InputItemsMap")
	List<RecordItems> findByDisplayGroup(@Param("uId") Integer uid);

	
	/*@Select("SELECT rig.UID,rig.DISPLAY_GROUP,rig.DISPLAY_GROUP_ORDER,rig.PLANNED_TIME,ri.ACTION_ITEM,ri.ACTION_ITEM_ORDER,ri.ANSWER_TYPE,ri.ANSWER,r.ANSWER AS SELECTED_ANSWER FROM mst_record_items_group AS rig LEFT JOIN mst_record_items AS ri ON rig.UID = ri.DISPLAY_GROUP LEFT JOIN tbl_records AS r ON ri.ACTION_ITEM = r.ACTION_ITEM AND r.EXECUTION_DATE = STR_TO_DATE('9/26/2013','%m/%d/%Y')  AND r.HCS_ID = #{hcsId} ORDER BY rig.DISPLAY_GROUP_ORDER,ri.ACTION_ITEM_ORDER")
	*/
	@Select("SELECT rig.UID,rig.DISPLAY_GROUP,rig.DISPLAY_GROUP_ORDER,rig.PLANNED_TIME,ri.ACTION_ITEM,ri.ACTION_ITEM_ORDER,ri.ANSWER_TYPE,ri.ANSWER,r.ANSWER AS SELECTED_ANSWER FROM mst_record_items_group AS rig LEFT JOIN mst_record_items AS ri ON rig.UID = ri.DISPLAY_GROUP LEFT JOIN tbl_records AS r ON ri.ACTION_ITEM = r.ACTION_ITEM AND r.EXECUTION_DATE = STR_TO_DATE(#{executionDate}, '%m/%d/%Y')  AND r.HCS_ID = #{hcsId} ORDER BY rig.DISPLAY_GROUP_ORDER,ri.ACTION_ITEM_ORDER")
	@ResultMap(value = "InputItemsSelectedMap")
	List<RecordItemViewMapper> findRecordItemsWithAnswers(
			@Param("hcsId") String patientId,
			@Param("executionDate") String date);

}